var amapFile = require('../../utils/amap-wx.js');
var util = require('../../utils/request.js');
var globalData = getApp().globalData;
//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    //预约中
    appointment: false,
    //使用中
    use: false,
    //已完成
    finish: {},
    //是否预约了地锁
    alreadyOrder: false,
    //预约地锁信息
    orderDeviceInfo: {},
    //地锁信息
    deviceInfo: {},
    //停车场信息
    addressInfo: {},
    headImg: '',
    //移动中心点经纬度
    centerLatitude: '',
    centerLongitude: '',
    choosePark: false,
    orderPark: false,
    chooseDS: false,
    finishPark: false,
    latitude: "",
    longitude: "",
    markers: [],
    parkType: '',
    selectAddress: false
  },
  // 点击停车场停车中信息去道闸停车
  toDZPark() {
    if (this.data.parkType == 'parking' && this.data.use == true) {
      wx.navigateTo({
        url: '../zdPark/zdPark',
      })
    }
  },
  // 一键解锁
  oneKey() {
    console.log(this.data.deviceInfo);
    var that = this;
    wx.showModal({
      title: '提示',
      content: '为了防止您的车位不被他人占用，请将您的爱车驾驶至车位前，再进行解锁！',
      success: (data) => {
        console.log(data);
        if (data.confirm) {
          wx.showLoading({
            title: '开锁中...',
            mask: true
          })
          util.req('/order/use', { 'uid': that.data.deviceInfo.deviceUid, 'memberId': globalData.memberId }, function (res) {
            console.log(res);
            wx.hideLoading();
            if (res.resultCode == 200) {
              wx.showToast({
                title: '开锁成功',
              })
              setTimeout(function () {
                wx.reLaunch({
                  url: '../index/index',
                })
              }, 500)
            } else {
              wx.showToast({
                title: res.resultMsg,
                icon: 'none'
              })
            }
          })
        }
      }
    })
  },
  // 导航
  navigation(e) {
    console.log(e);
    console.log(e.currentTarget)
    wx.openLocation({
      latitude: e.currentTarget.dataset.lat,
      longitude: e.currentTarget.dataset.lng,
      name: e.currentTarget.dataset.name,
      address: e.currentTarget.dataset.address
    })
  },
  // 收藏停车场
  collect() {
    console.log(1);
    var that = this;
    var data = {
      'memberId': globalData.memberId,
      'parkingId': this.data.addressInfo.parkingId
    };
    var url = '/collect/collect';
    var selectedList = [this.data.addressInfo.collectId]
    var isCollect = 'addressInfo.isCollect'
    var collectId = 'addressInfo.collectId'
    if (this.data.addressInfo.isCollect) {
      data = {
        'collectIds': selectedList
      }
      url = '/collect/delCollect'
    }
    console.log(data);
    util.req(url, data, function (res) {
      console.log(res);
      if (res.resultCode == 200) {
        wx.showToast({
          title: res.resultMsg,
        })
        that.setData({
          [isCollect]: !that.data.addressInfo.isCollect
        })
        if (that.data.addressInfo.isCollect) {
          that.setData({
            [collectId]: res.resultContent.collectId
          })
        }
      } else {
        wx.showToast({
          title: res.resultMsg,
          icon: 'none'
        })
      }
    })
  },
  // 强制结束订单
  finishOrder() {
    var that = this;
    wx.showModal({
      title: '提示',
      content: '为确保爱车不被刮蹭，请将您的爱车驶离车位后，再结束订单!',
      confirmText: '确认结束',
      success: function (res) {
        if (res.confirm) {
          console.log(that.data.orderDeviceInfo)
          wx.showLoading({
            title: '正在结束订单...',
            mask: true
          })
          util.req('/order/finish', { 'sn': that.data.orderDeviceInfo.sn, 'memberId': globalData.memberId, 'parkType': that.data.parkType }, function (res) {
            console.log(res);
            wx.hideLoading();
            if (res.resultCode == 200) {
              wx.navigateTo({
                url: '../payOrder/payOrder?sn=' + that.data.orderDeviceInfo.sn,
              })
            } else {
              wx.showToast({
                title: res.resultMsg,
                icon: 'none'
              })
            }
          })
        } else if (res.cancel) {
          console.log('取消')
        }
      }
    })
  },
  //跳转到我的
  jumpMy: function () {
    if (!globalData.userInfo.isPhone) {
      wx.navigateTo({
        url: '../loginByTel/loginByTel',
      })
    } else {
      wx.navigateTo({
        url: '../mine/mine'
      })
    }
  },
  //跳转到我的消息页
  message: function () {
    wx.navigateTo({
      url: '../message/message'
    })
  },
  //预约地锁，发送请求
  orderDevice: function () {
    var that = this
    util.req('/order/appointment', { 'uid': this.data.deviceInfo.deviceUid, 'memberId': app.globalData.memberId }, function (success) {
      console.log(success);
      if (success.resultCode == 200) {
        that.setData({
          alreadyOrder: true,
          appointment: true,
          markers: [],
          orderPark: true,
          chooseDS: false
        })
        var memberId = globalData.memberId;
        wx.getLocation({
          type: 'gcj02',
          success: function (res) {
            var data = {
              centerLatitude: res.latitude,
              centerLongitude: res.longitude
            }
            console.log(res);
            that.unfinished(memberId, data);
          }
        })
        
        // var nowDate = new Date().getTime();
        // var remainingTime = success.resultContent.appointmentInvalidDate - nowDate;
        // console.log(remainingTime);
        // remainingTime = util.formatSeconds(remainingTime / 1000);
        // console.log(remainingTime);
        // setInterval(() => {
        //   var minuteTime = parseInt(remainingTime.slice(3, 5));
        //   var secondTime = parseInt(remainingTime.slice(-2));
        //   if (secondTime <= 0) {
        //     minuteTime --;
        //     secondTime = 59;
        //   } else {
        //     secondTime --;
        //   }

        //   remainingTime = minuteTime + ':' + secondTime;
        //   console.log(remainingTime);
        // }, 1000)
        var orderDeviceInfo = {
          appointmentInvalidDate: util.time(success.resultContent.appointmentInvalidDate),
          sn: success.resultContent.sn
        }
        that.setData({
          orderDeviceInfo: orderDeviceInfo
        })
      } else {
        wx.showToast({
          title: success.resultMsg,
          icon: 'none'
        })
      }

    })
  },
  //预约地锁
  orderPark: function () {
    var that = this
    util.req('/member/detail', { 'memberId': app.globalData.memberId }, function (success) {
      app.globalData.userInfo = success.resultContent;
      if (app.globalData.userInfo.isPhone == false) {
        wx.navigateTo({
          url: '../loginByTel/loginByTel'
        })
      } else {
        wx.showModal({
          title: '提示',
          content: '预约成功后开始计费，每个用户每天可免费取消1次（15分钟内），15分钟后或第二次取消都需支付对应停车费用。',
          confirmText: '确认预约',
          success: function (res) {
            if (res.confirm) {
              console.log('确认预约')
              that.orderDevice();
            } else if (res.cancel) {
              console.log('取消')
            }
          }
        })
      }
    })

  },
  //跳转到搜索目的地页
  goInput: function () {
    wx.navigateTo({
      url: '../destination/destination'
    })
  },
  //扫码开锁，判断用户是否已有手机号，不存在则跳转手机号验证
  DSpark: function () {
    var that = this;
    util.req('/member/detail', { 'memberId': app.globalData.memberId }, function (success) {
      app.globalData.userInfo = success.resultContent;
      if (app.globalData.userInfo.isPhone == false) {
        wx.navigateTo({
          url: '../loginByTel/loginByTel'
        })
      } else if (!that.data.use) {
        wx.scanCode({
          success: function (res) {
            console.log(res);
            // console.log('1111&.vb'.indexof('&'));v
            var code = res.result
            console.log(code);
            var uid = code.indexOf('uid=');
            uid = code.slice(uid + 4, uid + 9);
            var area = code.indexOf('area=');
            area = code.slice(area + 5, area + 9);
            uid = area + uid;
            console.log(uid);
            wx.showModal({
              title: '提示',
              content: '为确保您的车位不被他人占用，请将您的爱车驾驶至车位前，再进行解锁！',
              confirmText: '确认开锁',
              success: (data) => {
                console.log(data);
                if (data.confirm) {
                  wx.showLoading({
                    title: '开锁中...',
                    mask: true
                  })
                  util.req('/order/use', { 'uid': uid, 'memberId': globalData.memberId }, function (res) {
                    console.log(res);
                    wx.hideLoading();
                    if (res.resultCode == 200) {
                      wx.showToast({
                        title: '开锁成功',
                      })
                      setTimeout(function () {
                        wx.reLaunch({
                          url: '../index/index',
                        })
                      }, 500)
                    } else if(res.resultCode == 400) {
                      wx.showToast({
                        title: res.resultCode,
                        icon: 'none'
                      })
                    } else {
                      wx.showToast({
                        title: '降锁失败，请重试',
                        icon: 'none'
                      })
                    }
                  })
                }
              }
            })
          }
        })
      }
    })
  },
  //地图视野变化时 获取周边地锁
  regionchange: function (e) {
    console.log(e);
    console.log(this.data.alreadyOrder);
    var that = this;
    if (this.data.alreadyOrder == false) {
      if (e.type == 'end') {
        this.setData({
          choosePark: false,
          orderPark: false,
          chooseDS: false
        })
        var that = this;
        var data;
        this.mapCtx.getCenterLocation({
          success: function (res) {
            data = {
              centerLatitude: res.latitude,
              centerLongitude: res.longitude
            }
            that.aroundSitePark(data);
            // that.setData({
            //   latitude: res.latitude,
            //   longitude: res.longitude
            // })
          }
        })
      }
    }
  },
  //取消预约
  cancelOrder: function () {
    var that = this;
    util.req('/order/cancel', { 'sn': this.data.orderDeviceInfo.sn, 'memberId': globalData.memberId }, function (success) {
      console.log(success)
      if (success.resultCode == 200) {
        that.setData({
          choosePark: false,
          orderPark: false,
          chooseDS: false,
          alreadyOrder: false,
          use: false,
          appointment: false,
          parkType: ''
        })
        that.mapCtx.getCenterLocation({
          success: function (res) {
            var data = {
              centerLatitude: res.latitude,
              centerLongitude: res.longitude
            }
            that.aroundSitePark(data);
            // that.setData({
            //   latitude: res.latitude,
            //   longitude: res.longitude
            // })
          }
        })
      } else if (success.resultCode == 300) {
        wx.showModal({
          title: '提示',
          content: '您今天的免费取消预约次数已用完或超出免费取消时间，需支付对应停车费用。',
          confirmText: '去支付',
          cancelText: '继续预约',
          success: function (res) {
            if (res.confirm) {
              console.log('去支付')
              util.req('/order/finish', { 'sn': that.data.orderDeviceInfo.sn, 'memberId': globalData.memberId, 'parkType': that.data.parkType }, function (res) {
                console.log(res);
                if (res.resultCode == 200) {
                  that.setData({
                    choosePark: false,
                    orderPark: false,
                    appointment: false,
                    chooseDS: false,
                    alreadyOrder: false,
                    use: false
                  })
                  wx.navigateTo({
                    url: '../payOrder/payOrder?sn=' + that.data.orderDeviceInfo.sn,
                  })
                } else if(res.resultCode == 400) {
                  wx.showToast({
                    title: res.resultMsg,
                    icon: 'none'
                  })
                } else {
                  wx.showToast({
                    title: '支付错误！',
                    icon: 'none'
                  })
                }
              })
            } else if (res.cancel) {
              console.log('取消')
            }
          }
        })
      }
    })
  },
  //获取周边停车场和地锁
  aroundSitePark: function (position) {
    this.setData({
      markers: []
    })
    var that = this;
    this.mapCtx.getCenterLocation({
      success: function (res) {
        console.log(res);
        console.log(position);
          var data = {
            latitude: position.centerLatitude,
            longitude: position.centerLongitude
          }
          // that.setData({
          //   centerLatitude: res.latitude,
          //   centerLongitude: res.longitude
          // })
        util.req('/parking/aroundSite', data, function (success) {
          console.log(data);
          console.log(success)
          if (success.resultCode == 200) {
            var markers = [];
            var oneMarker = {};
            var resultContent = success.resultContent;
            console.log(resultContent)
            resultContent.map(function (item, index) {
              oneMarker = {
                id: index,
                width: 36,
                height: 39,
                latitude: item.lat,
                longitude: item.lng,
                parkType: item.type,
                callout: {}
              }
              if (item.type == 'parking') {
                oneMarker.parkingId = item.parkingId
                oneMarker.iconPath = '../../img/disuopark.png'
              } else {
                oneMarker.uid = item.uid
                oneMarker.iconPath = '../../img/disuocopy 7@2x.png'
              }
              markers.push(oneMarker);
            })
            that.setData({
              markers: markers
            })
            console.log(that.data.markers)
          } else {
            wx.showToast({
              title: res.resultContent,
              icon: 'none'
            })
          }
        })
      }
    })
  },
  // 编号开锁
  DZpark: function () {
    var that = this;
    if(!this.data.use) {
      var myAmapFun = new amapFile.AMapWX({ key: '14c7d5a7fe1f44284eabe3eb47800d59' });
      myAmapFun.getRegeo({
        success: function (data) {
          //成功回调
          console.log(data);
          var code = data[0].regeocodeData.addressComponent.adcode;
          console.log(code);
          util.req('/device/area', { 'areaId': code }, function (res) {
            console.log(res);
            if (res.resultCode == 200) {
              if (res.resultContent.deviceCode == 'none') {
                wx.showToast({
                  title: '该地区暂未开通运营，敬请期待！',
                  icon: 'none'
                })
              } else {
                wx.navigateTo({
                  url: '../parkCode/parkCode?adcode=' + res.resultContent.deviceCode
                })
              }
            } else {
              wx.showToast({
                title: '该地区暂未开通运营，敬请期待！',
                icon: 'none'
              })
            }
          })
        },
        fail: function (info) {
          //失败回调
          console.log(info)
        }
      })
    }
  },
  // 点击控件 定位、跳转故障报修页面、客服
  controltap(e) {
    if (e.controlId == 0) {
      this.mapCtx.moveToLocation();
    }
    if (e.controlId == 1) {
      wx.navigateTo({
        url: '../repairs/repairs'
      })
    }
    if (e.controlId == 2) {
      wx.navigateTo({
        url: '../customerService/customerService'
      })
    }
  },
  // 去支付页面
  goPay: function () {
    wx.navigateTo({
      url: '../payOrder/payOrder?sn=' + this.data.finish.sn
    })
  },
  //查看是否有未完成的订单
  unfinished: function (memberId, data) {
    var that = this
    var deviceInfo;
    var orderDeviceInfo;
    var markers;
    var oneMarker;
    this.setData({
      markers: []
    })
    util.req('/order/unfinished', { 'memberId': memberId, 'lng': data.centerLongitude, 'lat': data.centerLatitude }, function (success) {
      console.log(success)
      //如果存在未完成订单，显示
      if (success.resultCode == 200) {
        if (success.resultContent.type == 'device') {
          //预约中
          if (success.resultContent.orderStatus == "appointment") {
            deviceInfo = {
              deviceName: success.resultContent.name,
              deviceAddress: success.resultContent.address,
              // deviceCharging: success.resultContent.charging,
              deviceUid: success.resultContent.uid,
              lat: success.resultContent.lat,
              lng: success.resultContent.lng,
              // chargingInterval: success.resultContent.chargingInterval,
              show: success.resultContent.show || ''
            }
            orderDeviceInfo = {
              appointmentInvalidDate: util.time(success.resultContent.appointmentInvalidDate),
              sn: success.resultContent.sn
            }
            markers = [];
            oneMarker = {};
            oneMarker = {
              latitude: success.resultContent.lat,
              longitude: success.resultContent.lng,
              iconPath: '../../img/disuocopy 7@2x.png',
              width: 66,
              height: 70,
              parkType: success.resultContent.type,
              callout: {
                content: success.resultContent.duration + "分钟·" + success.resultContent.mileage + "KM",
                fontSize: 14,
                color: "#666666",
                borderRadius: 5,
                padding: 5,
                bgColor: "#ffffff",
                display: "ALWAYS",
              }
            }
            markers.push(oneMarker);
            that.setData({
              orderPark: true,
              alreadyOrder: true,
              appointment: true,
              deviceInfo: deviceInfo,
              markers: markers,
              orderDeviceInfo: orderDeviceInfo,
              parkType: success.resultContent.type
            })
          } else if (success.resultContent.orderStatus == "use") {
            //使用中
            markers = [];
            oneMarker = {};
            oneMarker = {
              latitude: success.resultContent.lat,
              longitude: success.resultContent.lng,
              iconPath: '../../img/use8@3x.png',
              width: 66,
              height: 70,
              parkType: success.resultContent.type,
            }
            orderDeviceInfo = {
              sn: success.resultContent.sn
            }
            markers.push(oneMarker);
            that.setData({
              use: true,
              alreadyOrder: true,
              markers: markers,
              orderDeviceInfo: orderDeviceInfo,
              parkType: success.resultContent.type,
            })
          } else {
            //已完成
            var finish = {
              duration: util.formatSeconds(success.resultContent.orderDuration),
              amount: success.resultContent.amount,
              sn: success.resultContent.sn
            }
            markers = [];
            oneMarker = {};
            oneMarker = {
              latitude: success.resultContent.lat,
              longitude: success.resultContent.lng,
              iconPath: '../../img/disuocopy 7@2x.png',
              width: 66,
              height: 70,
              parkType: success.resultContent.type,
            }
            markers.push(oneMarker);
            that.setData({
              use:false,
              finishPark: true,
              alreadyOrder: true,
              appointment: false,
              markers: markers,
              finish: finish,
              parkType: success.resultContent.type
            })
          }
        } else {
          if (success.resultContent.orderStatus == "use") {
            //使用中
            // orderDeviceInfo = {
            //   sn: success.resultContent.sn
            // }
            var addressInfo = {
              parkingName: success.resultContent.name,
              parkingAddress: success.resultContent.address,
              parkingStartTime: success.resultContent.startTime,
              parkingEndTime: success.resultContent.endTime,
              // prkingCharging: success.resultContent.charging,
              parkingVacancy: success.resultContent.vacancy,
              parkingId: success.resultContent.parkingId,
              isCollect: success.resultContent.isCollect,
              collectId: success.resultContent.collectId,
              lat: success.resultContent.lat,
              lng: success.resultContent.lng,
              // chargingInterval: success.resultContent.chargingInterval
              show: success.resultContent.show || ''
            }
            // markers.push(oneMarker);
            that.setData({
              use: true,
              alreadyOrder: true,
              addressInfo: addressInfo,
              parkType: success.resultContent.type
            })
          } else {
            //已完成
            var finish = {
              duration: util.formatSeconds(success.resultContent.orderDuration),
              amount: success.resultContent.amount,
              sn: success.resultContent.sn
            }
            // markers = [];
            // oneMarker = {};
            // oneMarker = {
            //   latitude: success.resultContent.lat,
            //   longitude: success.resultContent.lng,
            //   iconPath: '../../img/disuocopy 7@2x.png',
            //   width: 66,
            //   height: 70,
            //   parkType: success.resultContent.type,
            // }
            // markers.push(oneMarker);
            that.setData({
              use: false,
              finishPark: true,
              alreadyOrder: true,
              finish: finish
            })
          }
        }
      }
      //如果不存在未完成订单，加载周边地锁和停车场信息
      else if (success.resultCode == 300) {
        console.log(data)
        that.aroundSitePark(data);
      }
    })
  },
  //页面加载时，获取周边停车场和地锁信息
  onLoad: function (res) {
    var that = this;
    console.log(res);
    this.mapCtx = wx.createMapContext('map');
    var userInfo = wx.getStorageSync('XPuserInfo');
    if (userInfo == '') {
      wx.redirectTo({
        url: '../authorization/authorization',
      })
    } else {
      this.setData({
        headImg: userInfo.userInfo.avatarUrl
      })
      // 跳转到选择的地址
      var name = 'amap.name';
      var latitude = 'amap.latitude';
      var longitude = 'amap.longitude';
      if (res.keywords != undefined) {
        var location = res.location.split(',');
        console.log(location);
        this.setData({
          latitude: location[1],
          longitude: location[0],
          selectAddress: true
        })
      }

      
    }
    // 添加控件
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          controls: [{
            id: 0, //定位图标
            iconPath: '../../img/dingwei@2x.png',
            position: {
              left: 10,
              top: res.windowHeight - 110,
              width: res.windowWidth / 7,
              height: res.windowWidth / 7
            },
            clickable: true
          },
          {
            id: 1,//保修图标
            iconPath: '../../img/baoxiu@2x.png',
            position: {
              left: 10,
              top: res.windowHeight - 60,
              width: res.windowWidth / 7,
              height: res.windowWidth / 7
            },
            clickable: true
          },
          {
            id: 2,//客服图标
            iconPath: '../../img/kefu@2x.png',
            position: {
              left: res.windowWidth - res.windowWidth / 5.5,
              top: res.windowHeight - 60,
              width: res.windowWidth / 7,
              height: res.windowWidth / 7
            },
            clickable: true
          },
          // {
          //   id: 3,//中心点图标
          //   iconPath: '../../img/center.png',
          //   position: {
          //     left: res.windowWidth / 2 - res.windowWidth / 20 / 2,
          //     top: res.windowHeight / 2 - res.windowWidth / 25 - res.windowWidth / 20 - 2,
          //     width: res.windowWidth / 20,
          //     height: res.windowWidth / 10
          //   },
          //   clickable: true
          // }
          ]
        })
      },
    })
  },
  //获取地锁信息
  deviceInfo: function (markerId, id, latitude, longitude) {
    var that = this
    util.req('/device/info', { 'uid': id, 'lng': longitude, 'lat': latitude }, function (success) {
      console.log(success);
      //console.log(markerId)
      var deviceInfo = {
        deviceId: markerId,
        deviceName: success.resultContent.name,
        deviceAddress: success.resultContent.address,
        // deviceCharging: success.resultContent.charging,
        deviceUid: success.resultContent.uid,
        lat: success.resultContent.lat,
        lng: success.resultContent.lng,
        // chargingInterval: success.resultContent.chargingInterval
        show: success.resultContent.show || ''
      }
      var callout = {
        content: success.resultContent.duration + "分钟·" + success.resultContent.mileage + "KM",
        fontSize: 14,
        color: "#666666",
        borderRadius: 5,
        padding: 5,
        bgColor: "#ffffff",
        display: "ALWAYS",
      }
      console.log(callout)
      var c = "markers[" + markerId + "].callout";
      if(that.data.markers[markerId].width > 36) {
        that.setData({
          [c]: callout,
          deviceInfo: deviceInfo
        })
      }
      console.log(that.data.markers[markerId].callout)
    })
  },
  //获取停车场信息
  parkingInfo: function (markerId, id, latitude, longitude) {
    var that = this
    util.req('/parking/info', { 'parkingId': id, 'lng': longitude, 'lat': latitude, 'memberId': globalData.memberId }, function (success) {
      console.log(success.resultContent);
      console.log(that.data.markers[markerId])
      var addressInfo = {
        parkingName: success.resultContent.name,
        parkingAddress: success.resultContent.address,
        parkingStartTime: success.resultContent.startTime,
        parkingEndTime: success.resultContent.endTime,
        // prkingCharging: success.resultContent.charging,
        parkingVacancy: success.resultContent.vacancy,
        parkingId: success.resultContent.parkingId,
        isCollect: success.resultContent.isCollect,
        collectId: success.resultContent.collectId,
        lat: success.resultContent.lat,
        lng: success.resultContent.lng,
        // chargingInterval: success.resultContent.chargingInterval
        show: success.resultContent.show || ''
      }
      var callout = {
        content: success.resultContent.duration + "分钟·" + success.resultContent.mileage + "KM",
        fontSize: 14,
        color: "#666666",
        borderRadius: 5,
        padding: 5,
        bgColor: "#ffffff",
        display: "ALWAYS",
      }
      console.log(callout)
      var c = "markers[" + markerId + "].callout";
      that.setData({
        [c]: callout,
        addressInfo: addressInfo
      })
      console.log(that.data.addressInfo)
      console.log(that.data.markers[markerId].callout)
    })
  },
  markertap: function (e) {
    var that = this;
    console.log(this.data.markers[e.markerId])
    var parkType = this.data.markers[e.markerId].parkType;
    var id;
    var width = "markers[" + e.markerId + "].width";
    var height = "markers[" + e.markerId + "].height";
    var callout = "markers[" + e.markerId + "].callout.display";
    wx.getLocation({
      type: 'gcj02',
      success: function (res) {
        var latitude = res.latitude;
        var longitude = res.longitude;
        //未预约的才能点击预约,已预约的则展示预约信息
        if (that.data.alreadyOrder == false) {
          if (that.data.markers[e.markerId].width <= 36) {
            if (parkType == 'parking') {
              //点击标记发送请求
              id = that.data.markers[e.markerId].parkingId;
              that.setData({
                chooseDS: false,
                orderPark: false,
                choosePark: true
              })
              that.parkingInfo(e.markerId, id, latitude, longitude)
            } else {
              id = that.data.markers[e.markerId].uid;
              that.setData({
                chooseDS: true,
                orderPark: false,
                choosePark: false
              })
              //调用接口，获取信息
              that.deviceInfo(e.markerId, id, latitude, longitude)
            }
            var itemWidth, itemHeight, itemcallout;
            that.data.markers.forEach(function (item) {
              //如果大的，变小
              if (item.id != e.markerId) {
                itemWidth = "markers[" + item.id + "].width";
                itemHeight = "markers[" + item.id + "].height";
                itemcallout = "markers[" + item.id + "].callout.display";
                if(item.width > 36) {
                  that.setData({
                    [itemWidth]: 36,
                    [itemHeight]: 39,
                    [itemcallout]: "",
                  })
                }
                // if(item.callout.display)
              } else {
                //如果是小的，变大
                that.setData({
                  [width]: 66,
                  [height]: 70
                })
              }
            })
          } else if (that.data.markers[e.markerId].width > 36) {
            that.setData({
              [width]: 36,
              [height]: 39,
              [callout]: "",
              chooseDS: false,
              orderPark: false,
              choosePark: false
            })
          }

        }
      }
    })

    // console.log(this.data.markers[e.markerId].callout)

  },
  onShow() {
    var that = this;
    var userInfo = wx.getStorageSync('XPuserInfo');
    // this.mapCtx = this.mapCtx || wx.createMapContext('map');
    if (userInfo == '') {
      wx.redirectTo({
        url: '../authorization/authorization',
      })
    } else {
        wx.getLocation({
          type: 'gcj02',
          success: function (res) {
            // 检查一下是否登录，登录后在获取未完成订单
            var timer = setInterval(() => {
              if(globalData.memberId != null) {
                var latitude = res.latitude
                var longitude = res.longitude
                var speed = res.speed
                var accuracy = res.accuracy
                var memberId = globalData.memberId;
                //console.log(memberId)
                if (!that.data.selectAddress) {
                  that.setData({
                    latitude: latitude,
                    longitude: longitude
                  })
                }
                var data = {
                  centerLatitude: that.data.latitude,
                  centerLongitude: that.data.longitude
                }
                console.log(data)
                //先看有没有未完成订单(预约中，使用中，未付款)
                that.unfinished(memberId, data);
                clearInterval(timer);
              }
            }, 500)
          }
        })
    }
  }
})
